<extend name="./public/frame.html"/>
<block name="content">
    <notempty name="type">
        <div class="layui-row">
            <div class="layui-col-xs6 layui-col-md4 layui-col-lg3">
                <div class="layui-btn-group">
                    <button class="layui-btn layui-btn-warm" data-type="add">添加APP版本</button>
                </div>
            </div>
        </div>
    </notempty>
    <table class="layui-table"
           lay-data="{width:'auto', height:'auto', url:'{:url('Version/user_app')}', page: true, limit: 10, id:'version'}" lay-filter="version">
        <thead>
        <tr>
            <th lay-data="{checkbox:true, fixed: true}"></th>
            <th lay-data="{field:'id', width:70, fixed: true, sort: true,align:'center'}">ID</th>
            <th lay-data="{field:'andriod_num', width:150,templet: '#andriod_status',align:'center'}">安卓版本号</th>
            <th lay-data="{field:'andriod_url',width:200,align:'center'}">安卓URL</th>
            <th lay-data="{field:'andriod_content', width:200,align:'center'}">Android更新内容</th>
            <th lay-data="{field:'ios_num', width:150,templet: '#ios_status',align:'center'}">IOS版本号</th>
            <th lay-data="{field:'ios_url', width:200,align:'center'}">IOS_URL</th>
            <th lay-data="{field:'ios_content', width:200,align:'center'}">IOS更新内容</th>
            <th lay-data="{field:'time', width:170, sort: true,align:'center'}">时间</th>
            <th lay-data="{field:'type',toolbar: '#types', width:100,align:'center' }">类型</th>
            <th lay-data="{fixed:'right', toolbar: '#barDemo', width:100, align:'center'}">操作</th>
        </tr>
        </thead>
    </table>

    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="edit" style="width: 70px">修改</a>
    </script>
    <script type="text/html" id="types">
        {{# if(d.type == 1){ }}
        乘客端
        {{# }else if(d.type == 2){ }}
        城内司机端
        {{# }else if(d.type == 3){ }}
        城际司机端
        {{# } }}
    </script>
    <script type="text/html" id="andriod_status">
        {{d.andriod_num}}
        {{# if(d.andriod_status == 1){ }}
        (强制升级)
        {{# } }}
    </script>
    <script type="text/html" id="ios_status">
        {{d.ios_num}}
        {{# if(d.ios_status == 1){ }}
        (强制升级)
        {{# } }}
    </script>
    <script>
        layui.use('table', function () {
            var table = layui.table;
            //监听工具条
            table.on('tool(version)', function (obj) {
                var data = obj.data;
                var id = obj.data.id;
                if (obj.event === 'edit') {
                    layer.open({
                        type: 2,
                        title: '编辑',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['100%', '100%'],
                        content: "{:url('version/edit','id=')}" + id, //iframe的url
                        cancel: function (index, layero) {
                            table.reload('version', {url: '/admin/version/user_app'});
                        }
                    });
                }
            });
            var $ = layui.jquery, active = {
                 add: function () {
                    layer.open({
                        type: 2,
                        title: $(this).text(),
                        shadeClose: true,
                        shade: 0.8,
                        area: ['100%', '100%'],
                        content: '{:url("/admin/version/add")}', //iframe的url
                        cancel: function (index, layero) {
                            table.reload('version', {url: '/admin/version/user_app'});
                        }
                    });
                }
            };
            $('.layui-btn').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
        });

    </script>
</block>
